package com.hezhiqin.netty.im.server.handler;

import com.hezhiqin.netty.im.protocol.IMMessage;
import com.hezhiqin.netty.im.server.processor.MsgProcessor;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.util.concurrent.EventExecutorGroup;
import lombok.extern.slf4j.Slf4j;

/**
 * @program: homeWork
 * @description:
 * @author: hezhiqin
 * @create: 2020-01-06 14:27
 */
@Slf4j
public class TerminalServerHandler extends SimpleChannelInboundHandler<IMMessage> {

    private MsgProcessor msgProcessor = new MsgProcessor();

    protected void channelRead0(ChannelHandlerContext ctx, IMMessage msg) throws Exception {
        msgProcessor.processor(ctx.channel(),msg);
    }


    /**
     * 异常处理
     */
    @Override
    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
        log.info("Socket Client: 与客户端断开连接:" + cause.getMessage());
        cause.printStackTrace();
        ctx.close();
    }

}
